package com.example.server.controller;

import com.example.server.domain.Maintenance;
import com.example.server.service.MaintenanceService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@CrossOrigin(origins = "*",allowCredentials = "true",allowedHeaders = "*",methods = {RequestMethod.GET,RequestMethod.POST,RequestMethod.DELETE,RequestMethod.PUT,RequestMethod.OPTIONS})
@Controller
@RequestMapping("/maintenance")
public class MaintenanceController {
    private final MaintenanceService maintenanceService;

    public MaintenanceController(MaintenanceService maintenanceService) {
        this.maintenanceService = maintenanceService;
    }



    @RequestMapping("/create")
    @ResponseBody
    public void createMaintenance(@RequestBody Maintenance maintenance) {
        maintenance.setStatus("待修理");
        maintenanceService.createMaintenance(maintenance);
    }
    @RequestMapping("/delete")
    @ResponseBody
    public void deleteMaintenance(Long id) {
        maintenanceService.deleteMaintenance(id);
    }
    @RequestMapping("/querybyid")
    @ResponseBody
    public Maintenance getMaintenanceById(Long id) {
        return maintenanceService.getMaintenanceById(id);
    }
    @RequestMapping("/update")
    @ResponseBody
    public void updateMaintenance(@RequestBody Maintenance maintenance) {
        maintenanceService.updateMaintenance(maintenance);
    }

    @RequestMapping("/resolve")
    @ResponseBody
    public void resolveMaintenance(Long id) {
        maintenanceService.resolveMaintenance(id);
    }
    @RequestMapping("/queryall")
    @ResponseBody
    public List<Maintenance> getAllMaintenance() {
        return maintenanceService.getAllMaintenance();
    }
    @RequestMapping("/querylike")
    @ResponseBody
    public List<Maintenance> querylike(String content) {
        return maintenanceService.querylike(content);
    }
}
